﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;
using WMI.NET.CIM;

namespace WMI.NET.ComputerSystemHardware.VideoAndMonitor
{
    /// <summary>
    /// The Win32_DesktopMonitor WMI class represents the type of monitor or display device attached to the computer system. Starting with Windows Vista, properties of this class replace Win32_DisplayConfiguration.
    /// Starting with Windows Vista, hardware that is not compatible with Windows Display Driver Model (WDDM) returns inaccurate property values for instances of this class.
    /// Windows Server 2003 and Windows XP:  This class returns data supplied by hardware compatible with Windows Device Driver Model (WDDM).
    /// </summary>
    public class Win32_DesktopMonitor : CIM_DesktopMonitor
    {

        private string _MonitorManufacturer;
        private string _MonitorType;
        private Nullable<UInt32> _PixelsPerXLogicalInch;
        private Nullable<UInt32> _PixelsPerYLogicalInch;

        /// <summary>
        /// Name of the monitor manufacturer.
        /// Example: "NEC"
        /// </summary>
        public string MonitorManufacturer { get { return _MonitorManufacturer; } }

        /// <summary>
        /// Type of monitor.
        /// Example: "NEC 5FGp"
        /// </summary>
        public string MonitorType { get { return _MonitorType; } }

        /// <summary>
        /// Resolution along the x-axis (horizontal direction) of the monitor.(Pixels per Logical Inch) 
        /// </summary>
        public Nullable<UInt32> PixelsPerXLogicalInch { get { return _PixelsPerXLogicalInch; } }

        /// <summary>
        /// Resolution along the y-axis (vertical direction) of the monitor.(Pixels per Logical Inch) 
        /// </summary>
        public Nullable<UInt32> PixelsPerYLogicalInch { get { return _PixelsPerYLogicalInch; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_DesktopMonitor(ManagementBaseObject mbo)
            : base(mbo)
        {
            _MonitorManufacturer = mbo.GetStringValue("MonitorManufacturer");
            _MonitorType = mbo.GetStringValue("MonitorType");
            _PixelsPerXLogicalInch = mbo.GetUIntValue("PixelsPerXLogicalInch");
            _PixelsPerYLogicalInch = mbo.GetUIntValue("PixelsPerYLogicalInch");
        }


    }

    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_DesktopMonitors : Win32Collection<Win32_DesktopMonitor>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_DesktopMonitor> GetCollection()
        {
            List<Win32_DesktopMonitor> tempCollection = new List<Win32_DesktopMonitor>();

            foreach (var s in searcher.Get())
            {
                Win32_DesktopMonitor tempListItem = new Win32_DesktopMonitor(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_DesktopMonitors() : base("SELECT * FROM Win32_DesktopMonitor") { }

    }

}
